Challenge: Copy Tree
Let’s copy a binary tree.
We'll cover the following
Problem#
Given a binary tree, copy its values to another binary tree.
Input#
A binary tree.
Output#
A new binary tree with the data of the given binary tree.
Sample input#
The root node t.root of a binary tree will be our input, for which we have to generate a copy tree. We’ll generate this new tree by using the copyTree() function.
Sample output#
A CopyTree() function will return a tree, which we’ll use to pass the test case.
If the copied tree is identical to the original tree, the sample output will be true.
Sample output#
true
Coding exercise#
Try to solve this yourself first. If you get stuck or need help, you can always press the “Show Solution” button to see how your problem can be solved. We’ll look at the solution in the next lesson.
Good luck!
main.go
tree.go
Solution Review: Identical Trees
Solution Review: Copy Tree